//
//  ASSession+AppID.m
//  AppleAuth
//
//  Created by 吴双 on 2023/1/23.
//

#import "ASSession+AppID.h"
#import "ASSession+Private.h"
#import <AltSign/AltSign.h>

@implementation ASTeamSession (AppID)

/* App IDs */
- (void)fetchAppIDs:(void (^_Nullable)(NSArray<ALTAppID *> * _Nullable appIDs, NSError * _Nullable error))completion {
    [[ALTAppleAPI sharedAPI] fetchAppIDsForTeam:self.team session:self.session completionHandler:completion];
}

- (void)addAppIDWithName:(NSString * _Nonnull)name
        bundleIdentifier:(NSString * _Nonnull)bundleIdentifier
               completed:(void (^ _Nullable)(ALTAppID *_Nullable appID, NSError *_Nullable error))completion {
    [[ALTAppleAPI sharedAPI] addAppIDWithName:name bundleIdentifier:bundleIdentifier
                                         team:self.team
                                      session:self.session
                            completionHandler:completion];
}

- (void)updateAppID:(ALTAppID * _Nonnull)appID completionHandler:(void (^ _Nonnull)(ALTAppID * _Nullable appID, NSError * _Nullable error))completionHandler {
    [[ALTAppleAPI sharedAPI] updateAppID:appID team:self.team session:self.session completionHandler:completionHandler];
}

- (void)deleteAppID:(ALTAppID * _Nonnull)appID completionHandler:(void (^ _Nonnull)(BOOL success, NSError *_Nullable error))completionHandler {
    [[ALTAppleAPI sharedAPI] deleteAppID:appID forTeam:self.team session:self.session completionHandler:completionHandler];
}

/* App Groups */
- (void)fetchAppGroups:(void (^_Nonnull)(NSArray<ALTAppGroup *> *_Nullable groups, NSError *_Nullable error))completionHandler {
    [[ALTAppleAPI sharedAPI] fetchAppGroupsForTeam:self.team session:self.session completionHandler:completionHandler];
}

- (void)addAppGroupWithName:(NSString * _Nonnull)name
            groupIdentifier:(NSString * _Nonnull)groupIdentifier
          completionHandler:(void (^_Nonnull)(ALTAppGroup *_Nullable group, NSError *_Nullable error))completionHandler {
    [[ALTAppleAPI sharedAPI] addAppGroupWithName:name
                                 groupIdentifier:groupIdentifier
                                            team:self.team session:self.session
                               completionHandler:completionHandler];
}

- (void)assignAppID:(ALTAppID * _Nonnull)appID
           toGroups:(NSArray<ALTAppGroup *> * _Nonnull)groups
  completionHandler:(void (^_Nonnull)(BOOL success, NSError *_Nullable error))completionHandler {
    [[ALTAppleAPI sharedAPI] assignAppID:appID toGroups:groups team:self.team session:self.session completionHandler:completionHandler];
}

@end
